package com.industrial.operation.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.industrial.common.core.utils.StringUtils;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import com.industrial.operation.domain.OperationCityCheck;
import com.industrial.operation.service.IOperationCityCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * 十六市地市考核Controller
 * 
 * @author ruoyi
 * @date 2024-03-28
 */
@RestController
@RequestMapping("/city/check")
public class OperationCityCheckController extends BaseController
{
    @Autowired
    private IOperationCityCheckService operationCityCheckService;

    /**
     * 查询十六市地市考核列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OperationCityCheck operationCityCheck)
    {
        startPage();
        List<OperationCityCheck> list = operationCityCheckService.selectOperationCityCheckList(operationCityCheck);
        return getDataTable(list);
    }

    /**
     * 导出十六市地市考核列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, OperationCityCheck operationCityCheck)
    {
        List<OperationCityCheck> list = operationCityCheckService.selectOperationCityCheckList(operationCityCheck);
        ExcelUtil<OperationCityCheck> util = new ExcelUtil<OperationCityCheck>(OperationCityCheck.class);
        util.exportExcel(response, list, "十六市地市考核数据");
    }

    /**
     * 获取十六市地市考核详细信息
     */

    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(operationCityCheckService.selectOperationCityCheckByBaseId(baseId));
    }

    /**
     * 新增十六市地市考核
     */

    @PostMapping
    public AjaxResult add(@RequestBody OperationCityCheck operationCityCheck)
    {
        return toAjax(operationCityCheckService.insertOperationCityCheck(operationCityCheck));
    }

    /**
     * 修改十六市地市考核
     */

    @PutMapping
    public AjaxResult edit(@RequestBody OperationCityCheck operationCityCheck)
    {
        return toAjax(operationCityCheckService.updateOperationCityCheck(operationCityCheck));
    }

    /**
     * 删除十六市地市考核
     */

	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(operationCityCheckService.deleteOperationCityCheckByBaseIds(baseIds));
    }

    @PostMapping("/importCityCheckInfo")
    public AjaxResult importCityCheckInfo(@RequestPart("file") MultipartFile file,String years){
        if(file.isEmpty()){
            throw new RuntimeException("没有找到上传的文件");
        }
        return operationCityCheckService.importCityCheckInfo(file,years);
    }

    /**
     * 查询十六市考核排名
     * @return
     */
    @GetMapping("/cityCheckOrder")
    public AjaxResult cityCheckOrder(OperationCityCheck params){
        Map<String, List<String>> resultMap = operationCityCheckService.cityCheckOrder(params);
        return AjaxResult.success(resultMap);
    }

    /**
     * 十六地市指标统计
     * @param params
     * @return
     */
    @GetMapping("/cityIndexCheckOrder")
    public AjaxResult cityIndexCheckOrder(OperationCityCheck params){
        Map<String, List<String>> resultMap = operationCityCheckService.cityIndexCheckOrder(params);
        return AjaxResult.success(resultMap);
    }

    /**
     * 十六市历年考核评价得分趋势
     * @param params
     * @return
     */
    @GetMapping("/cityJnScroe")
    public AjaxResult cityJnScroe(OperationCityCheck params){
        if(StringUtils.isBlank(params.getYears())){
            return AjaxResult.warn("请选择导入的年份");
        }
        Map<String, Object> resultMap = operationCityCheckService.cityJnScroe(params);
        return AjaxResult.success(resultMap);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<OperationCityCheck> util = new ExcelUtil<OperationCityCheck>(OperationCityCheck.class);
        util.importTemplateExcel(response, "十六地市考核","十六地市考核");
    }
}
